<template>
  <div id="config" :style="`font-size:`+subjectFont">
      <div id="ul-style">
          <el-collapse >
                <el-collapse-item :title="ul_style[0].name" :name="1" :class="darkOrLight === true?'dark':' '">
                    <div class="collapse-item-box">
                        <div v-for="(p,i) in ul_style[0].selectItem" class="selectItem" :key="i" @click="changeSubColor(p),addClass()" :style="`background-color:`+p"> 

                        </div>
                        <el-color-picker class="selectItem" v-model="selectColor" @click="undefine = false"></el-color-picker>
                    </div>
                </el-collapse-item>
              <el-collapse-item :title="ul_style[1].name" :name="2" :class="darkOrLight === true?'dark':' '">
                    <div class="collapse-item-box">
                        <div class="selectItem" v-for="(p,i) in ul_style[1].selectItem" :key="i" @click="changeSubFont(p),addClass()" :style="`font-size:`+p"> 
                            新闻
                        </div>
                    </div>
                </el-collapse-item>
          </el-collapse>
      </div>
      <div id="ul-mode">
          <ul>
              <template v-for="(item,index) in ul_mode">
                <li :key="index" :class="darkOrLight == true?'Dark':' '">
                  <span>{{item.name}}</span>
                  <el-switch
                    v-model="item.modeValue"
                    active-color="#13ce66"
                    inactive-color="#ff4949">
                  </el-switch>
                </li>
              </template>
          </ul>
      </div>
  </div>
</template>

<script>
import { mapMutations,mapState } from 'vuex'
import { Message } from 'element-ui'
export default {
    name:'Config',
    data() {
        return {
            currentA:0,
            currentB:1,
            ul_style:[
                {name:'主题',selectItem:['red','black','orange','pink','blue','#999','red']},
                {name:'字体',selectItem:['10px','16px','20px','24px']},
            ],
            ul_mode:[
                {name:'日间/夜间模式',modeValue:false},
            ],
            selectColor:'#409EFF',
            undefine :true
        }
    },
    methods:{
        ...mapMutations({changeSubColor:'SetSubjectColor'}),
        ...mapMutations({changeSubFont:'SetSubjectFont'}),
        addClass(){
            Message({
                    showClose: true,
                    message: '修改成功',
                    type: 'success'
            });
        },
    },
    computed:{
        ...mapState(['subjectFont']),
        darkOrLight(){
            return this.ul_mode[0].modeValue
        }
    },
    watch:{
        selectColor:{
            handler(newvalue){
                this.$store.commit('SetSubjectColor',newvalue)
            }
        },
        ul_mode:{
            deep:true,
            handler(newValue,oldValue){
                console.log(newValue,oldValue)
                //this.$bus .$emit('DarkOrLight',newValue[0].modeValue)
                this.$store.commit('DarkOrLight',newValue[0].modeValue)
            }
        }
    }
}
</script>

<style scoped lang="less">
    #config{
        font-size: 1.1rem;
        display: block!important;
        #ul-style{
            margin: 0 0 2rem 0;
            .collapse-item-box{
                width: 100%;
                height: 130px;
                display: flex;
                justify-content: center;
                flex-flow: row wrap;
                align-items:center;
                /deep/.selectItem,.el-color-picker__trigger{
                    box-sizing: border-box;
                    width: 60px;
                    height: 60px;
                    margin: 5px;
                    cursor: pointer;
                    border-radius: 20px;
                    overflow: hidden;
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    flex-flow: row;
                }
            }
            
        }
        #ul-mode{
            margin: 2rem 0;
            li{
                display: flex;
                align-items: center;
                height: 48px;
                line-height: 48px;
                background-color: #FFF;
                color: #303133;
                cursor: pointer;
                border-bottom: 1px solid #EBEEF5;
                font-size: 13px;
                font-weight: 500;
                transition: border-bottom-color .3s;
                outline: 0;
                justify-content: space-between;
            }
            .Dark{
                background-color:rgb(34,33,38);
                border-bottom: 1px solid rgb(52,55,64);
                color: #fff;
            }
        }
    }
    .selectAcitve{
        border: 5px rgb(51,112,255) solid;
    }
    /deep/.el-color-picker__trigger{
        box-sizing: border-box;
        width: 80px;
        height: 80px;
        cursor: pointer;
        border-radius: 20px;
    }
    /deep/.el-color-picker__color {
        position: unset;
    }
    .dark{
        /deep/.el-collapse-item__header{
            background-color:rgb(34,33,38);
            border-bottom: 1px solid rgb(52,55,64);
            color: #fff;
        }
        /deep/.el-collapse-item__wrap {
            background-color:rgb(34,33,38);
            border-bottom: 1px solid rgb(52,55,64);
            color: #fff!important;
        }
        .selectItem{
            color: #fff!important;
        }
    }
    
</style>